import logging

import pytest

from resource.pom.settings import Settings
from utils.manager import Direction


# @pytest.fixture(autouse=True)
# def set_language(device):
#     logging.info('方法前置----设置系统语言与地区为中文----')
#     device.set_param('persist.global.language','zh-Hans')
#     device.set_param('persist.global.locale','zh-Hans-CN')
#     yield
#     logging.info('方法后置----恢复系统语言与地区为中文')
#     device.set_param('persist.global.language', 'zh-Hans')
#     device.set_param('persist.global.locale', 'zh-Hans-CN')


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device, factory_reset):
        logging.info('步骤1.进入桌面，点击设置-系统-语言设置-语言与地区-语言')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.dirc_fling(Direction.Down)
        device.click(*self.app.system_item)
        device.refresh_layout()
        device.click_element(device.get_element_by_text('语言设置'))
        device.refresh_layout()
        device.click_element(device.get_element_by_text('语言与地区'))
        logging.info('预期结果1.可正常进入语言设置')
        device.refresh_layout()
        device.assert_text_exist('简体中文')
        device.assert_text_exist('添加语言')

        logging.info('步骤2.点击添加语言')
        device.click_element(device.get_element_by_text('添加语言'))
        device.refresh_layout()
        device.click_element(device.get_element_by_text('English'))
        device.refresh_layout()
        device.click_element(device.get_element_by_text('更改'))
        logging.info('预期结果2.选择添加并更改为该语言后桌面所有信息都显示为该语言')
        device.refresh_layout()
        device.assert_text_exist('Add Language')
        device.go_back()
        device.refresh_layout()
        device.assert_text_exist('Set Language')
        device.go_back()
        device.refresh_layout()
        device.assert_text_exist('System & Updates')
        device.go_back()
        device.refresh_layout()
        device.assert_text_exist('Privacy')
        device.assert_text_exist('Users & Accounts')
        device.assert_text_exist('System & Updates')
